#ifndef _LIBS_H
#define _LIBS_H

#include "list.h"

#define MAX_LINK_LEN 255
#define MAX_CHAPTER_NAME_LEN 255
struct file_link{
	struct list_head list; //linux list

	int chapter; //chapter index, 0-based
	char chapter_name[MAX_CHAPTER_NAME_LEN];
	size_t offset; //offset bytes of this chapter
	size_t len; //len bytes of this chapter, first
};


extern char chapter0_name[];
extern char default_regex_str[];
//book-toc.html
extern const char toc_html_head[];
extern const char toc_html_tail[];
//toc.ncx
extern const char toc_ncx_head[];
extern const char toc_ncx_mid[];
extern const char toc_ncx_content[];

//content.opf
extern const char opf_head[];
extern const char opf_mid[];
extern const char opf_tail[];

//html content
extern const char novel_content_head[];
extern const char novel_content_mid[];

extern void parse_title_name(char* path, char* title);
extern void set_novel_name(char* name);
extern char* get_novel_name(void);

extern void init_list(struct file_link* head, size_t total_size);
//name, len: chapter name
//offset: chapter offset
extern void insert_list(struct file_link* head, char* name, size_t len,
	size_t offset);
extern void destroy_list(struct file_link* head);

//win7 console: couldn't output the UTF-8 string
//so convert utf-8 to gb2312 for debugging
extern void FWRITE_IGNORE(char* buf, int size, int count);

extern int build_toc(char* buf, long size, struct file_link* head);
extern int output_book_toc(char* buf, char* title, struct file_link* head);
extern int output_cover(char* buf, char* title);
extern int output_ncx(char* buf, char* title, struct file_link* head);
extern int output_opf(char* buf, char* title, struct file_link* head);
extern int output_html(char* buf, char* title, struct file_link* head);
extern void output_mobi(char* title);

#endif
